/*******************************************************************************
 * RegistrationAction.java
 *
 * Created by Nishan
 * Last modified Date: Oct 8, 2008 10:15:49 AM by nishan
  * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ******************************************************************************/

package com.printeverywhere.action;

import static com.printeverywhere.util.LinksConstants.ADMIN_EDIT_PROFILE;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ValidationAware;
import com.printeverywhere.delegator.BanneddomainsDelegator;
import com.printeverywhere.delegator.CommonFunctionDelegator;
import com.printeverywhere.delegator.GeneralOptionsServiceDelegator;
import com.printeverywhere.delegator.LocationCategoriesServiceDelegator;
import com.printeverywhere.delegator.PromotionalCodesServiceDelegator;
import com.printeverywhere.delegator.TranslationSystemServiceDelegator;
import com.printeverywhere.delegator.UserServiceDelegator;
import com.printeverywhere.dto.AffiliateSettings;
import com.printeverywhere.dto.Banneddomain;
import com.printeverywhere.dto.DateFormat;
import com.printeverywhere.dto.GeneralOptions;
import com.printeverywhere.dto.Languages;
import com.printeverywhere.dto.LocationCategories;
import com.printeverywhere.dto.MailingSystem;
import com.printeverywhere.dto.NumberFormat;
import com.printeverywhere.dto.PromotionalCode;
import com.printeverywhere.dto.Timezones;
import com.printeverywhere.dto.User;
import com.printeverywhere.dto.UserAffiliation;
import com.printeverywhere.dto.UserRegistrationOptions;
import com.printeverywhere.dto.UsersInfo;
import com.printeverywhere.interceptor.ApplicationContextInterceptor;
import com.printeverywhere.util.AdminConstants;
import com.printeverywhere.util.AttributeConstants;
import com.printeverywhere.util.CommonUtil;
import com.printeverywhere.util.DateUtil;
import com.printeverywhere.util.MailHelper;
import com.printeverywhere.util.SearchCriteria;
import com.printeverywhere.util.SearchListCriteria;

// TODO: Auto-generated Javadoc
/**
 * The Class RegistrationAction.
 */
public class RegistrationAction extends FrontBaseSupport implements
		ValidationAware, ServletRequestAware {

	/**
	 * Instantiates a new registration action.
	 */
	public RegistrationAction() {
		super(false, false);
	}

	/** Logger for this class. */
	private static final Logger logger = Logger.getLogger(RegistrationAction.class);

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The action. */
	private String action;

	/** The terms. */
	private Boolean terms;

	/** The referal. */
	private String referal;

	/** The request. */
	private HttpServletRequest request;

	/** The confirm passowrd. */
	private String confirmPassword;

	/** The user id. */
	private Integer userId;

	/** The timezone id. */
	private Integer timezoneId;

	/** The search list criteria. */
	private SearchListCriteria searchListCriteria = new SearchListCriteria();

	/** The user. */
	private User user;

	/** The numberFormat list. */
	private List<NumberFormat> numberFormatList = UserServiceDelegator
			.getNumberFormatList();

	/** The language list. */
	private List<Languages> languageList = TranslationSystemServiceDelegator
			.getList();

	/** The dateFormat list. */
	private List<DateFormat> dateFormatList = UserServiceDelegator
			.getDateFormatList();

	/** The region list. */
	private List<LocationCategories> regionList = getRegionListByLevel();

	/** The state list. */
	private List<LocationCategories> countryList = new ArrayList<LocationCategories>();

	/** The timezone list. */
	private List<Timezones> timezoneList = UserServiceDelegator
			.getTimezoneList();

	/** The state list. */
	private List<LocationCategories> stateList = new ArrayList<LocationCategories>();

	private List<UserRegistrationOptions> registrationPageOptionList = new ArrayList<UserRegistrationOptions>();

	private GeneralOptions generalOptions;

	private PromotionalCode codeData;

	public PromotionalCode getCodeData() {
		return codeData;
	}

	public void setCodeData(PromotionalCode codeData) {
		this.codeData = codeData;
	}

	public GeneralOptions getGeneralOptions() {
		return generalOptions;
	}

	public void setGeneralOptions(GeneralOptions generalOptions) {
		this.generalOptions = generalOptions;
	}

	/**
	 * Gets the country list by level.
	 *
	 * @return the country list by level
	 */
	public List<LocationCategories> getRegionListByLevel() {
		searchListCriteria.removeAllAttribute();
		searchListCriteria.setAsc(true);
		searchListCriteria.setOrderBy(AdminConstants.CATEGORYNAME);
		searchListCriteria.setAttribute(AdminConstants.LEVEL, new Object[] {
		AdminConstants.ONE_NUMBER, SearchListCriteria.EQ });
		return LocationCategoriesServiceDelegator.getList(searchListCriteria);
	}

	/**
	 * Populate registration form.
	 *
	 * @return the string
	 *
	 * @throws Exception the exception
	 */
	public String populateRegistrationForm() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("populateRegistrationForm() - start"); //$NON-NLS-1$
		}

		action = "submitRegistrationForm.htm";

		String countryCode=null;
		try{
			countryCode= CommonUtil.getCountryCodeByIP(request.getRemoteAddr());
		}catch (Exception e) {
			countryCode = "US";
		}
		if(countryCode.equals("XX") || countryCode.length() > 2)countryCode = "US";

		timezoneId = UserServiceDelegator.getTimeZoneId(countryCode);

		if (this.request.getParameter(AttributeConstants.REFERAL) != null) {
			this.referal = this.request.getParameter(AttributeConstants.REFERAL);
		}

		if (logger.isDebugEnabled()) {
			logger.debug("populateRegistrationForm() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	/**
	 * Submit registration.
	 *
	 * @return the string
	 *
	 * @throws Exception the exception
	 */
	public String submitRegistration() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("submitRegistration() - start"); //$NON-NLS-1$
		}
		User referal = null;
		String captchaId = null;
		if(request.getSession().getAttribute(nl.captcha.servlet.Constants.SIMPLE_CAPCHA_SESSION_KEY) != null || request.getSession().getAttribute(nl.captcha.servlet.Constants.SIMPLE_CAPCHA_SESSION_KEY) == ""){
			captchaId = request.getSession().getAttribute(nl.captcha.servlet.Constants.SIMPLE_CAPCHA_SESSION_KEY).toString();
		}
		
		// retrieve the response
		String captchaResponse = request
				.getParameter(AttributeConstants.CAPTCHA);

		/*if(terms == false){
			addActionError("Please Accept Tearms and Condition");
			return INPUT;
		}*/

		if (UserServiceDelegator.getUserByEmail(user.getEmail()) != null) {
			addActionError("User is registered with this Email Id Please try another");
			return INPUT;
		}

		if (UserServiceDelegator.getUserByUserId(user.getUserId()) == null) {
			if (captchaId.equals(captchaResponse)) {
				if (user.getUserId() != null) {
					if (this.referal != null
							&& this.referal.trim().length() > 0) {
						referal = UserServiceDelegator.getUser(Integer
								.parseInt(CommonUtil.decrypt(this.referal)));
						user.setUser(referal);
					}

					try {
						if(request.getParameter("user.promotionalCode") == null || request.getParameter("user.promotionalCode") == ""){

						}else{
							String promotionalCode = request.getParameter("user.promotionalCode");
							codeData = PromotionalCodesServiceDelegator.getPromotionalCodeFromCode(promotionalCode);
							if(codeData == null || codeData.getUser() != null){
								addActionError("Please Enter valid Promotional Code");
								return INPUT;
							}
						}
						generalOptions = GeneralOptionsServiceDelegator.getGeneralOptions();
						if(codeData != null && codeData.getMoney() != 0){
							this.user.setCurrentBalance((generalOptions.getNewAccountDeposit()) + (codeData.getMoney()));
						}else{
							this.user.setCurrentBalance(generalOptions.getNewAccountDeposit());
						}
						
						if(generalOptions.getAutoApproveNewUsers() == true){
							this.user.setActive(true);
							this.user.setActivationKey(null);
							addActionMessage("Your registration has been successful. You can login Here");
						}
						
						if(generalOptions.getRequiredCreditCardForNewAccount() == true){
							ActionContext.getContext().getSession().put("newUser", user);
							return "requiredcreditcard";
						}else{
							if(generalOptions.getAutoApproveNewUsers() == false){
								try {
									MailingSystem mailingSystem = (MailingSystem) ActionContext.getContext().getApplication().get(AdminConstants.MAILING_OPTIONS);
									MailHelper mailHelper = new MailHelper(mailingSystem.getServerAddress(), mailingSystem.getServerUsername(), mailingSystem.getServerPassword());

									StringBuffer URL = new StringBuffer();
									URL.append(CommonUtil.getLocalBasePath(request));
									URL.append("/mail/registerationConfirmationMail.htm?id=").append(user.getUserId()).append("&pass=").append(user.getPassword()).append("&uname=").append(user.getFirstName()).append("%20").append(user.getLastName()).append("&link=").append(user.getActivationKey());

									String message = CommonUtil.getURLContent(URL.toString());
									mailHelper.sendMail(mailingSystem.getAccountsConfirmationEmail(), user.getEmail(), "Account Confirmation", message);
									addActionMessage("Your registration has been successful; we have sent activation link to the email address given. Activate first and then login to account.");
								} catch (Exception e) {
									e.printStackTrace();
								}
							}
							UserServiceDelegator.insertUser(user);
						}

						UsersInfo usersInfo = new UsersInfo();
						usersInfo.setUser(user);
						CommonFunctionDelegator.generalInsertbyobj(usersInfo);

						if (this.referal != null && this.referal.trim().length() > 0) {
							AffiliateSettings affiliateSettings = (AffiliateSettings) ActionContext.getContext().getApplication().get(AdminConstants.AFFILIATE_PROGRAM);
							UserAffiliation userAffiliation = new UserAffiliation();
							userAffiliation.setUserByUserId(referal);
							userAffiliation.setUserByReferalUserId(user);
							userAffiliation.setIsPercentage(affiliateSettings.getIsPercentage());
							userAffiliation.setIsBonus(affiliateSettings.getIsBonus());
							userAffiliation.setStartDate(DateUtil.getTodaysDate());

							if (affiliateSettings.getIsPercentage()) {
								userAffiliation.setPercentageBonus(affiliateSettings.getBonusPercentage());
								userAffiliation.setChangePercentage(affiliateSettings.getPercentageChange());
								if (affiliateSettings.getPercentageValidTill() != 0) {
									userAffiliation.setEndDate(DateUtil.addDate(userAffiliation.getStartDate(), Calendar.MONTH, affiliateSettings.getPercentageValidTill()));
								}
								CommonFunctionDelegator.generalInsertbyobj(userAffiliation);
							}
							if (affiliateSettings.getIsBonus()) {
								if (affiliateSettings.getBonusValidTill() != 0) {
									userAffiliation.setBonusAvailable(affiliateSettings.getBonusAmount());
									userAffiliation.setEndDate(DateUtil.addDate(userAffiliation.getStartDate(), Calendar.MONTH, affiliateSettings.getBonusValidTill()));
									CommonFunctionDelegator.generalInsertbyobj(userAffiliation);
								}
								referal.setCurrentBalance(referal.getCurrentBalance() + affiliateSettings.getBonusAmount());
								UserServiceDelegator.updateUser(referal);
							}
						}

						if(codeData != null) {
							String promotionaluserId = request.getParameter("user.userId");
							User pramotionalUser = UserServiceDelegator.getUserByUserId(promotionaluserId);
							PromotionalCode code = PromotionalCodesServiceDelegator.get(codeData.getId());
							code.setUser(pramotionalUser);
							PromotionalCodesServiceDelegator.update(code);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}

					if (logger.isDebugEnabled()) {
						logger.debug("submitRegistration() - end"); //$NON-NLS-1$
					}

					//addActionMessage("Your registration has been successful; we have sent activation link to the email address given. Activate first and then login to account.");
					setLeftAllowed(true);
					setLoginPage(true);
					return SUCCESS;
				} else if (getActionErrors().size() > 0) {
					if (logger.isDebugEnabled()) {
						logger.debug("submitRegistration() - end"); //$NON-NLS-1$
					}
					return ERROR;
				} else {
					if (logger.isDebugEnabled()) {
						logger.debug("submitRegistration() - end"); //$NON-NLS-1$
					}
					return INPUT;
				}
			} else {
				if (logger.isDebugEnabled()) {
					logger.debug("submitRegistration() - end"); //$NON-NLS-1$
				}
				addActionError("Enter Valid Character for Captch Image");
				return INPUT;
			}
		} else {
			addActionError("User Id is already registered...");
			return INPUT;
		}
	}

	/**
	 * Edits the registration information.
	 *
	 * @return the string
	 *
	 * @throws Exception the exception
	 */
	public String updateRegistrationInformation() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("updateRegistrationInformation() - start"); //$NON-NLS-1$
		}

		setLeftAllowed(true);
		setMyAccount(true);
		User oldUserInfo = (User) request.getSession().getAttribute(AttributeConstants.USER);
		user.setActive(oldUserInfo.getActive());
		if(request.getParameter("user.email").trim().equals((((User) request.getSession().getAttribute(AttributeConstants.USER)).getEmail()).trim())){
			this.user.setEmail(user.getEmail());
		}else{
			if (UserServiceDelegator.getUserByEmail(user.getEmail()) != null) {
				addActionError("User is registered with this Email Id Please try another");
				return INPUT;
			}
		}
		try{
			registrationPageOptionList = (List<UserRegistrationOptions>) ActionContext.getContext().getApplication().get(AdminConstants.REGISTRATION_OPTIONS);

			if(!registrationPageOptionList.get(2).getEmail()){
				user.setEmail(oldUserInfo.getEmail());
			}
			if(!registrationPageOptionList.get(2).getFirstName()){
				user.setFirstName(oldUserInfo.getFirstName());
			}
			if(!registrationPageOptionList.get(2).getLastName()){
				user.setLastName(oldUserInfo.getLastName());
			}
			if(!registrationPageOptionList.get(2).getCompany()){
				user.setCompany(oldUserInfo.getCompany());
			}
			if(!registrationPageOptionList.get(2).getJobTitle()){
				user.setJobTitle(oldUserInfo.getJobTitle());
			}
			if(!registrationPageOptionList.get(2).getStreet()){
				user.setStreet(oldUserInfo.getStreet());
			}
			if(!registrationPageOptionList.get(2).getCity()){
				user.setCity(oldUserInfo.getCity());
			}
			if(!registrationPageOptionList.get(2).getZip()){
				user.setZip(oldUserInfo.getZip());
			}
			if(!registrationPageOptionList.get(2).getPhone()){
				user.setPhone(oldUserInfo.getPhone());
			}
			if(!registrationPageOptionList.get(2).getMobile()){
				user.setMobile(oldUserInfo.getMobile());
			}
			if(!registrationPageOptionList.get(2).getFax()){
				user.setFax(oldUserInfo.getFax());
			}
			if(!registrationPageOptionList.get(2).getWebSiteAddress()){
				user.setWebSiteAddress(oldUserInfo.getWebSiteAddress());
			}
			if(!registrationPageOptionList.get(2).getPromotionalCode()){
				user.setPromotionalCode(oldUserInfo.getPromotionalCode());
			}
			if(!registrationPageOptionList.get(2).getUserTimeZone()){
				user.setTimezones(oldUserInfo.getTimezones());
			}
			UserServiceDelegator.updateUser(user);
		}catch (Exception e) {
			e.printStackTrace();
		}
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.setAttribute(AttributeConstants.ID, user.getId());
		user = UserServiceDelegator.getList(searchCriteria).size() > 0?UserServiceDelegator.getList(searchCriteria).get(0): new User();
		request.getSession().setAttribute(AttributeConstants.USER, user);

		if (logger.isDebugEnabled()) {
			logger.debug("updateRegistrationInformation() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/**
	 * Update registration information.
	 *
	 * @return the string
	 *
	 * @throws Exception the exception
	 */
	public String editRegistrationInformation() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("editRegistrationInformation() - start"); //$NON-NLS-1$
		}

		setLeftAllowed(true);
		setMyAccount(true);
		action = "updateRegistrationForm.htm";
		user = (User) request.getSession()
				.getAttribute(AttributeConstants.USER);
		countryList = LocationCategoriesServiceDelegator.getCountryListByRegionId(user.getRegion().getCategoryId());
		stateList = LocationCategoriesServiceDelegator.getStateListByCountryId(user.getCountry().getCategoryId());

		if (logger.isDebugEnabled()) {
			logger.debug("editRegistrationInformation() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/**
	 * Gets the user information.
	 *
	 * @return the user information
	 *
	 * @throws Exception the exception
	 *
	 * @author ankur
	 *
	 * Gets the user information.
	 */
	public String getUserInformation() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("getUserInformation() - start"); //$NON-NLS-1$
		}

		action = ADMIN_EDIT_PROFILE;
		user = UserServiceDelegator.getUser(this.userId);
		countryList = LocationCategoriesServiceDelegator.getCountryListByRegionId(user.getRegion().getCategoryId());
		stateList = LocationCategoriesServiceDelegator.getStateListByCountryId(user.getCountry().getCategoryId());

		if (logger.isDebugEnabled()) {
			logger.debug("getUserInformation() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/**
	 * Gets the user.
	 *
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	/**
	 * Sets the user.
	 *
	 * @param user the new user
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 * Gets the country list.
	 *
	 * @return the country list
	 */
	public List<LocationCategories> getCountryList() {
		return countryList;
	}

	/**
	 * Gets the state list.
	 *
	 * @return the state list
	 */
	public List<LocationCategories> getStateList() {
		return stateList;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.opensymphony.xwork2.ActionSupport#validate()
	 */
	@Override
	public void validate() {
		if (logger.isDebugEnabled()) {
			logger.debug("validate() - start"); //$NON-NLS-1$
		}

		int index = 1;
		if(user.getId() != null && user.getId().intValue() != 0){
			index = 2;
		}

		registrationPageOptionList = (List<UserRegistrationOptions>) ActionContext.getContext().getApplication().get(AdminConstants.REGISTRATION_OPTIONS);

		if(this.user.getUserId() == null || this.user.getUserId().trim().equalsIgnoreCase(AdminConstants.NONE)){
			addActionError("User ID name is required");
		}
		if(this.user.getPassword() == null || this.user.getPassword().trim().equalsIgnoreCase(AdminConstants.NONE)){
			addActionError("Password is required");
		}
		if(getConfirmPassword() == null){
			addActionError("Confirm Password is required");
		}
		if(this.user.getRegion() == null){
			addActionError("Region is required");
		}
		if(this.user.getCountry() == null){
			addActionError("Country is required");
		}
		if(this.user.getState() == null){
			addActionError("State is required");
		}

		if(registrationPageOptionList.get(index).getEmail() && registrationPageOptionList.get(0).getEmail()){
			if(this.user.getEmail() == null || this.user.getEmail().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Email is required");
			}
		}
		if(registrationPageOptionList.get(index).getFirstName() && registrationPageOptionList.get(0).getFirstName()){
			if(this.user.getFirstName() == null || this.user.getFirstName().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("First Name is required");
			}
		}
		if(registrationPageOptionList.get(index).getLastName() && registrationPageOptionList.get(0).getLastName()){
			if(this.user.getLastName() == null || this.user.getLastName().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Last Name is required");
			}
		}
		if(registrationPageOptionList.get(index).getCompany() && registrationPageOptionList.get(0).getCompany()){
			if(this.user.getCompany() == null || this.user.getCompany().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Company is required");
			}
		}
		if(registrationPageOptionList.get(index).getJobTitle() && registrationPageOptionList.get(0).getJobTitle()){
			if(this.user.getJobTitle() == null || this.user.getJobTitle().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Job title is required");
			}
		}
		if(registrationPageOptionList.get(index).getStreet() && registrationPageOptionList.get(0).getStreet()){
			if(this.user.getStreet() == null || this.user.getStreet().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Street is required");
			}
		}
		if(registrationPageOptionList.get(index).getCity() && registrationPageOptionList.get(0).getCity()){
			if(this.user.getCity() == null || this.user.getCity().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("City is required");
			}
		}
		if(registrationPageOptionList.get(index).getZip() && registrationPageOptionList.get(0).getZip()){
			if(this.user.getZip() == null || this.user.getZip().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Zip is required");
			}
		}
		if(registrationPageOptionList.get(index).getPhone() && registrationPageOptionList.get(0).getPhone()){
			if(this.user.getPhone() == null || this.user.getPhone().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Phone is required");
			}
		}
		if(registrationPageOptionList.get(index).getMobile() && registrationPageOptionList.get(0).getMobile()){
			if(this.user.getMobile() == null || this.user.getMobile().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Mobile is required");
			}
		}
		if(registrationPageOptionList.get(index).getFax() && registrationPageOptionList.get(0).getFax()){
			if(this.user.getFax() == null || this.user.getFax().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Fax is required");
			}
		}
		if(registrationPageOptionList.get(index).getWebSiteAddress() && registrationPageOptionList.get(0).getWebSiteAddress()){
			if(this.user.getWebSiteAddress() == null || this.user.getWebSiteAddress().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Website is required");
			}
		}
		if(registrationPageOptionList.get(index).getPromotionalCode() && registrationPageOptionList.get(0).getPromotionalCode()){
			if(this.user.getPromotionalCode() == null || this.user.getPromotionalCode().trim().equalsIgnoreCase(AdminConstants.NONE)){
				addActionError("Promotional Code is required");
			}
		}
		if(registrationPageOptionList.get(index).getUserTimeZone() && registrationPageOptionList.get(0).getUserTimeZone()){
			if(this.user.getTimezones() == null){
				addActionError("Time Zone Format is required");
			}
		}
		if(registrationPageOptionList.get(index).getAgree() && registrationPageOptionList.get(0).getAgree()){
				if(terms == false){
					addActionError("Please Accept Tearms and Condition");
				}
			}

		String registrationEmial=request.getParameter("user.email");
		if(registrationEmial != null && !registrationEmial.equals("")){
			String[] result = registrationEmial.split("\\@");

			if(result.length>1){
				List<Banneddomain> blockDomain= BanneddomainsDelegator.getBannedDomainList(result[1]);
				List<Banneddomain> blockEmail= BanneddomainsDelegator.getBannedEmailList(registrationEmial);

				if(blockEmail != null || blockDomain != null){
					addActionError("Your email or domain is banned from registration on our site.");
				}
			}
		}

		if (request.getSession().getAttribute(AttributeConstants.USER) != null){
			setLeftAllowed(true);
			setMyAccount(true);
			action = "updateRegistrationForm.htm";
		}
		else
			action = "submitRegistrationForm.htm";
		super.validate();
		regionList = getRegionListByLevel();
		countryList = LocationCategoriesServiceDelegator.getCountryListByRegionId(Integer.parseInt(request.getParameter("user.region.categoryId")));
		stateList = LocationCategoriesServiceDelegator.getCountryListByRegionId(Integer.parseInt(request.getParameter("user.country.categoryId")));
		if(registrationPageOptionList.get(index).getUserTimeZone() && registrationPageOptionList.get(0).getUserTimeZone()){
			timezoneId = Integer.parseInt(request.getParameter("user.timezones.id"));
		}

		if (logger.isDebugEnabled()) {
			logger.debug("validate() - end"); //$NON-NLS-1$
		}
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
	 */

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	/**
	 * Sets the country list.
	 *
	 * @param countryList the new country list
	 */
	public void setCountryList(List<LocationCategories> countryList) {
		this.countryList = countryList;
	}

	/**
	 * Sets the state list.
	 *
	 * @param stateList the new state list
	 */
	public void setStateList(List<LocationCategories> stateList) {
		this.stateList = stateList;
	}

	/**
	 * Gets the number format list.
	 *
	 * @return the number format list
	 */
	public List<NumberFormat> getNumberFormatList() {
		return numberFormatList;
	}

	/**
	 * Sets the number format list.
	 *
	 * @param numberFormatList the new number format list
	 */
	public void setNumberFormatList(List<NumberFormat> numberFormatList) {
		this.numberFormatList = numberFormatList;
	}

	/**
	 * Gets the date format list.
	 *
	 * @return the date format list
	 */
	public List<DateFormat> getDateFormatList() {
		return dateFormatList;
	}

	/**
	 * Sets the date format list.
	 *
	 * @param dateFormatList the new date format list
	 */
	public void setDateFormatList(List<DateFormat> dateFormatList) {
		this.dateFormatList = dateFormatList;
	}

	/**
	 * Gets the language list.
	 *
	 * @return the language list
	 */
	public List<Languages> getLanguageList() {
		return languageList;
	}

	/**
	 * Sets the language list.
	 *
	 * @param languageList the new language list
	 */
	public void setLanguageList(List<Languages> languageList) {
		this.languageList = languageList;
	}

	/**
	 * Gets the timezone list.
	 *
	 * @return the timezone list
	 */
	public List<Timezones> getTimezoneList() {
		return timezoneList;
	}

	/**
	 * Sets the timezone list.
	 *
	 * @param timezoneList the new timezone list
	 */
	public void setTimezoneList(List<Timezones> timezoneList) {
		this.timezoneList = timezoneList;
	}

	/**
	 * Gets the action.
	 *
	 * @return the action
	 */
	public String getAction() {
		return action;
	}

	/**
	 * Sets the action.
	 *
	 * @param action the new action
	 */
	public void setAction(String action) {
		this.action = action;
	}

	/**
	 * Gets the confirm password.
	 *
	 * @return the confirm password
	 */
	public String getConfirmPassword() {
		return confirmPassword;
	}

	/**
	 * Sets the confirm password.
	 *
	 * @param confirmPassword the new confirm password
	 */
	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	/**
	 * Gets the user id.
	 *
	 * @return the user id
	 */
	public Integer getUserId() {
		return userId;
	}

	/**
	 * Sets the user id.
	 *
	 * @param userId the new user id
	 */
	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	/**
	 * Gets the referal.
	 *
	 * @return the referal
	 */
	public String getReferal() {
		return referal;
	}

	/**
	 * Sets the referal.
	 *
	 * @param referal the new referal
	 */
	public void setReferal(String referal) {
		this.referal = referal;
	}

	/**
	 * Gets the timezone id.
	 *
	 * @return the timezone id
	 */
	public Integer getTimezoneId() {
		return timezoneId;
	}

	/**
	 * Sets the timezone id.
	 *
	 * @param timezoneId the new timezone id
	 */
	public void setTimezoneId(Integer timezoneId) {
		this.timezoneId = timezoneId;
	}

	/**
	 * @return the terms
	 */
	public Boolean getTerms() {
		return terms;
	}

	/**
	 * @param terms the terms to set
	 */
	public void setTerms(Boolean terms) {
		this.terms = terms;
	}

	/**
	 * @return the regionList
	 */
	public List<LocationCategories> getRegionList() {
		return regionList;
	}

	/**
	 * @param regionList the regionList to set
	 */
	public void setRegionList(List<LocationCategories> regionList) {
		this.regionList = regionList;
	}

	public List<UserRegistrationOptions> getRegistrationPageOptionList() {
		return registrationPageOptionList;
	}

	public void setRegistrationPageOptionList(
			List<UserRegistrationOptions> registrationPageOptionList) {
		this.registrationPageOptionList = registrationPageOptionList;
	}

}